//
//  ZJFiltrateView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/11/22.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJFiltrateView.h"

@interface ZJFiltrateView ()
/** imageView */
@property (nonatomic, strong) UIImageView *imageView;
/** label */
@property (nonatomic, strong) UILabel *label;

@end
@implementation ZJFiltrateView

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self addSubview:self.label];
        [self addSubview:self.imageView];
        self.title = title;
    }
    return self;
}



- (void)setTitle:(NSString *)title{
    _title = title;
    self.label.text = title;
    CGFloat maxWidth = self.width - (15 + 5 + 5 + 5) * [UIScreen zj_screenWScale];
    CGFloat labelWidwth = [NSString zj_sizeOfString:title font:self.label.font width:maxWidth].width;
    
    CGFloat labeLeft = (self.width - labelWidwth - 20 * [UIScreen zj_screenWScale]) / 2;
    
    self.label.sd_layout
    .topSpaceToView(self, 0)
    .leftSpaceToView(self, labeLeft)
    .heightIs(self.height)
    .widthIs(labelWidwth);
    [self.label updateLayout];
    
    self.imageView.sd_layout
    .topEqualToView(self.label)
    .leftSpaceToView(self.label, 5 * [UIScreen zj_screenWScale])
    .heightIs(self.height)
    .widthIs(15 * [UIScreen zj_screenWScale]);
    [self.imageView updateLayout];
    
}


- (UIImageView *)imageView{
    if (_imageView == nil){
        _imageView = [[UIImageView alloc] init];
        _imageView.image = [UIImage imageNamed:@"sign_select_more"];
        _imageView.contentMode = UIViewContentModeCenter;
    }
    return _imageView;
}

- (UILabel *)label{
    if (_label == nil){
        _label = [UILabel new];
        _label.textColor = [UIColor textGrayColor];
        _label.adjustsFontSizeToFitWidth = YES;
        _label.font = [UIFont titleTextFont];
    }
    return _label;
}

@end
